<!-- 积分汇总 -->
<template>
	<view class="summary cl_flex_page">
		<view class="summary_list_item" v-for="item in list" :key="item.id">
			<text class="summary_list_item_name">{{item.shopName}}</text>
			<text class="summary_list_item_type">店铺类型：{{getTypeName(item.shopType)}}</text>
			<text class="summary_list_item_sum">积分汇总：{{item.total}}</text>
		</view>
		<cl-scroll-view ref="listRef" :api-fun="getList" :params="params" pageNumField="page">
			<template #list={list}>
				<view class="summary_list_item" v-for="item in list" :key="item.id">
						<text class="summary_list_item_sum">统计日期：{{item.statisticalTime}}</text>
						<text class="summary_list_item_sum">总积分：{{item.total}}</text>
				</view>
			</template>
		</cl-scroll-view>
	</view>
</template>

<script setup>
	import {
		ref
	} from 'vue'
	const userInfo = uni.getStorageSync('user')
	const list = ref([])
	const getShopInfo = async () => {
		let res = await uni.request({
			url: '/shop/shopStorePoints',
			method: 'POST',
			data: {
				userId: userInfo.id
			}
		})
		list.value = res
	}
	getShopInfo()

	const typeList = ref([])
	const getDict = async () => {
		typeList.value = (await uni.request({
			url: '/dictDetail',
			method: 'GET',
			data: {
				dictName: 'SHOPTYPE',
				enabled: 1,
				page: 0,
				size: 9999,
				userId: userInfo.id
			}
		}))?.records
	}
	getDict()

	const getTypeName = (type) => {
		if (!type) {
			return ''
		}
		let curType = typeList.value.find(item => item.value === type)
		return curType ? curType.label : ''
	}
	const params = ref({
		page: 1,
		size: 10,
		userId: userInfo.id
	})
	const getList = (data) => {
		return uni.request({
			url: '/shop/shopStorePointsItem',
			method: 'POST',
			data
		})
	}
</script>

<style scoped lang="scss">
	.summary {
		&_list {
			flex: 1;
			margin: 20rpx;

			&_item {
				margin: 20rpx;
				padding: 20rpx;
				box-sizing: border-box;
				display: flex;
				flex-direction: column;
				border-radius: 20rpx;
				background-color: #fff;

				&_name {
					font-size: 32rpx;
					font-weight: bold;
					margin-bottom: 10rpx;
				}

				&_type {
					font-size: 30rpx;
					margin-bottom: 10rpx;
				}

				&_sum {
					font-size: 30rpx;
				}
			}
		}
	}
</style>